--
-- Author: shunguo.chen
-- Date: 2018-06-07 11:52:10
--
-- TheatreTeam 大剧院队伍信息

local TheatreMember = import(".TheatreMember")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	self.members = {}
	if data then
		self:init(data)
	end
end

-- message TheatreTeam {
-- 	int 	teamId = 1; //队伍id(0代表左边，1代表右边)
-- 	int32	lifeNum = 2; //剩余生命条数
-- 	repeated Member members = 3; // 队员基本信息
-- }
function ClassRef:init(data)
	self.teamId = data.teamId
	self.lifeNum = data.lifeNum

	self:updateMembers(data.members)
end

function ClassRef:updateMembers(members)
	local myMember
	for i,v in ipairs(members) do
		local member = self.members[i]
		if not member then
			member = TheatreMember.new()
			self.members[i] = member
		end
		member:init(v)
		if member:isMe() then
			myMember = member
		end
	end
	self._myMember = myMember
end

function ClassRef:getTeamName()
	if self._myMember then
		return self._myMember:getName()
	else
		return self.members[1]:getName()
	end
end

function ClassRef:isMyTeam()
	return self._myMember ~= nil
end

function ClassRef:getMembers()
	return self.members
end

return ClassRef